package com.meusconcursos;

import com.meusconcursos.dto.Cargo;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

public class CargoListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_cargo);
		setTitle(R.string.titulo_lista_cargo);

		ArrayAdapter<Cargo> adapter = new ArrayAdapter<Cargo>(this,
				android.R.layout.simple_list_item_1,
				MeusConcursosActivity.dbHelper
						.getCargosFromEdital((String) getIntent()
								.getExtras().get("id_edital")));
		setListAdapter(adapter);

		this.getListView().setOnItemClickListener(
				new AdapterView.OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parentView, View childView,
							int position, long id) {
						
						Cargo cargo = (Cargo) parentView.getItemAtPosition(position);
						
						Intent intent = new Intent(getBaseContext(),
								FormacaoListActivity.class);

						intent.putExtra("id_cargo", cargo.getId());

						startActivity(intent);						

					}
				});

	}

}
